package com.exam.system.controller;

import com.exam.system.entity.QuestionAndOptionDTO;
import com.exam.system.entity.QuestionOption;
import com.exam.system.entity.ResponseEntity;
import com.exam.system.service.ExamQuestionOptionService;
import com.exam.system.service.ExamQuestionService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/option/")
public class ExamQuestionOptionController {
    @Autowired
    private ExamQuestionOptionService examQuestionOptionService;


    @ApiOperation(value="根据试题id 查找该试题下所有的题目选项")
    @ApiImplicitParam(name="id",value="试题id",required = true)
    //根据题目id查题目下的所有选项
    @GetMapping("getOptionsByQuesId")
    public  ResponseEntity<List<QuestionOption>> getOptionsByQuesId(Integer id) {
        List<QuestionOption> optionsByQuesId = examQuestionOptionService.getOptionsByQuesId(id);
        ResponseEntity<List<QuestionOption>> responseEntity=new ResponseEntity<>(200,"禁用成功",optionsByQuesId);
        return responseEntity;
    }

    @ApiOperation(value="对返回的封装类进行操作，修改试题选项")
    @ApiImplicitParam(name="dto",value="试题选项封装类，包含试题，试题选项，正确答案id，标签id",required = true)
    @PostMapping("updateQuestionAndOptions")
    public ResponseEntity<Object> updateQuestionAndOptions(@RequestBody QuestionAndOptionDTO dto){
        examQuestionOptionService.updateQuestionAndOptions(dto);
        ResponseEntity<Object> responseEntity=new ResponseEntity<>(200,"修改成功",null);
        System.out.println(dto);
        return responseEntity;
    }

    @ApiOperation(value="对返回的封装类进行操作，增加试题及其试题选项")
    @ApiImplicitParam(name="dto",value="试题选项封装类，包含试题，试题选项，正确答案id，标签id",required = true)
    @PostMapping("addQuestionAndOptions")
    public ResponseEntity<Object> addQuestionAndOptions(@RequestBody QuestionAndOptionDTO dto){
        examQuestionOptionService.addQuestionAndOptions(dto);
        ResponseEntity<Object> responseEntity=new ResponseEntity<>(200,"修改成功",null);
        return responseEntity;
    }


}
